<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>hello react</title>
</head>

<body>
    <div id="test1"></div>
    <div id="test2"></div>
    <div id="test3"></div>

    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <!-- 对标签属性的限制 -->
    <script type="text/javascript" src="../js/prop-types.js"></script>

    <script type="text/babel">
        //创建组件
        class Person extends React.Component {

            render() {
                console.log(this);
                const {name,age,sex} = this.props
                return (
                    <ul>
                        <li>{name}</li>
                        <li>{age}</li>
                        <li>{sex}</li>
                    </ul>
                )
            }
        }
        //检验规则
        Person.propTypes ={
            name:PropTypes.string.isRequired, //字符串类型,必传
            sex:PropTypes.string,
            age:PropTypes.number,
            speak:PropTypes.func//限制speak为函数
        }
        //默认值
        Person.defaultProps={
            sex:'未知',
            age:18
        }
        
        //渲染组件到页面
        ReactDOM.render(<Person name="tom" age={19} sex="男" speak={speak}/>,document.getElementById('test1') )
        ReactDOM.render(<Person name="jeery" age={29} sex="女"/>,document.getElementById('test2') )
        //批量传递抱标签属性
        const p = {name:'qaz',age:18,sex:'男'}
        ReactDOM.render(<Person {...p}/>,document.getElementById('test3') )

        function speak(){
            console.log("我说话了");
        }
    </script>
</body>
</body>

</html>